home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / t_sys5 / unixcpio.gz / unixnet.cpio / mulport.c < prev    next >
C/C++ Source or Header  |  1994-07-11  |  10KB  |  245 lines

  1. #include "config.h"
  2. #ifdef MULPORT
  3. #include <stdio.h>
  4. #include "global.h"
  5. #include "mbuf.h"
  6. #include "iface.h"
  7. #include "ax25.h"
  8. #include <ctype.h>
  9. #ifdef    UNIX
  10. #include <string.h>
  11. #endif
  12.  
  13. /**************************************************************************
  14. * The struct mulrep holds calls and interface names for multiport         *
  15. * repeating                                                               *
  16. * port[] holds the interface name passed back to hack in ax25.c           *
  17. **************************************************************************/
  18. typedef struct {
  19.      struct    ax25_addr dcall;    /* digipeater callsign */
  20.      char port[4];            /* port name */
  21. } mulrep;
  22.  
  23.  
  24. #define TRUE 1
  25. #define FALSE 0
  26.  
  27.  
  28.  
  29. /****************************************************************************
  30. * Multiport system globals                                                  *
  31. * mport is the multiport flag initialized to false until mulport is called. *
  32. ****************************************************************************/
  33. int       mport = FALSE;
  34. mulrep    destrpt[10], extbl[10], lan;
  35.  
  36. /*************************************************************************
  37. * mulport fills the array of structures of digi calls to which packets   *
  38. * may  be repeated and sets the global flag mport TRUE. It reads from    *
  39. * the file DIGILIST which must be in the ROOT directory and is formatted *
  40. * <callsign+ssid> <interface_name>                                       *
  41. * example:                                                               *
  42. * KE4ZV-1 ax0                                                            *
  43. * KD4NC-1 ax1                                                            *
  44. * mulport also builds an array of destination calls from the file EXLIST *
  45. * in the root directory for destinations not fitting the general rules.  *
  46. * This is the function called when the command "mulport on" is given.    *
  47. *************************************************************************/
  48. /*ARGSUSED*/
  49. int mulport(argc,argv)
  50. int argc;
  51. char *argv[];
  52. {
  53.  FILE *fp, *fopen();
  54.  int       x;
  55.  char tcall[12], tport[4];
  56.  char str[257];
  57.  int tmp;
  58.  
  59.  if (strncmp(argv[1],"on",2)==0){
  60.       if ((fp = fopen("/digilist","r")) == 0) {
  61.           printf("Could not open file DIGILIST\n");
  62.           return(FALSE);
  63.       }
  64.       setcall(&(lan.dcall),"lan");
  65.       strcpy(lan.port,"");
  66.       printf("\nDigi Call          Interface\n");
  67.       for (x=0; (x <= 9) && (fgets(str, 256, fp)); x++) {
  68.           /* make sure we clear out the whole line to the \n   */
  69.           /* otherwise, any other  whitespace after the port  */
  70.           /* designator will fubar the parser                 */
  71.           tmp = sscanf(str, "%s %s", tcall, tport);
  72.           if (tmp!= 2) {    /* make sure we don't do a partial entry */
  73.             printf("Invalid record in DIGILIST encountered, record ignored\n");
  74.             continue;
  75.           }
  76.           printf("%9.9s       %6.6s\n",tcall,tport);
  77.  
  78. /*  we really need to verify that the port  exists before we put it into the
  79.     table or direct a stream to it. Current default behavior is to send the
  80.     packet back out the port it came in on if there is no match.
  81. */
  82.           setcall(&(destrpt[x].dcall),tcall);
  83.           strcpy(destrpt[x].port,tport);
  84. #ifdef MULBUG
  85.           printf("%9.9s      %6.6s\n",destrpt[x].dcall.call,destrpt[x].port);
  86. #endif
  87.      }
  88.       fclose(fp);
  89. /*finish out the array with null entries */
  90.       strcpy(tcall,'\0');
  91.       strcpy(tport,'\0');
  92.       for(;x<=9;x++){
  93.           setcall(&(destrpt[x].dcall),tcall);
  94.           strcpy(destrpt[x].port,tport);
  95.       }
  96.       /*****************************************************************
  97.       *    This code builds the exception list extbl[]                 *
  98.       *    This list handles destination calls who need behavior that  *
  99.       *    does not follow the mulport rules ie: a user station on the *
  100.       *    high speed trunk.                                           *
  101.       *****************************************************************/
  102.       if ((fp = fopen("/exlist","r")) == 0) {
  103.           printf("Could not open file EXLIST\n");
  104.           return(FALSE);
  105.       }
  106.       printf("\nException Call          Interface\n");
  107.       for (x=0; (x <= 9) && (fgets(str, 256, fp)); x++) {
  108.           tmp = sscanf(str, "%s %s", tcall, tport);
  109.           if (tmp!= 2) {    /* make sure we don't do a partial entry */
  110.             printf("Invalid record in EXLIST encountered, record ignored\n");
  111.             continue;
  112.           }
  113.           printf("%9.9s       %6.6s\n",tcall,tport);
  114.           setcall(&(extbl[x].dcall),tcall);
  115.           strcpy(extbl[x].port,tport);
  116. #ifdef MULBUG
  117.           printf("%9.9s      %6.6s\n",extbl[x].dcall.call,extbl[x].port);
  118. #endif
  119.      }
  120.       fclose(fp);
  121. /*finish out the array with null entries */
  122.       strcpy(tcall,'\0');
  123.       strcpy(tport,'\0');
  124.       for(;x<=9;x++){
  125.           setcall(&(destrpt[x].dcall),tcall);
  126.           strcpy(destrpt[x].port,tport);
  127.       }
  128.       mport = TRUE;
  129.       return(TRUE);
  130.  } else {
  131.      mport = FALSE;
  132.      return(FALSE);
  133.  }
  134.  
  135. }
  136.  
  137. /**************************************************************************
  138. * Here is the repeater hack called from ax_recv in module ax25.c.         *
  139. * Repeater searches the array of digi calls created by mulport for the    *
  140. * digi call following ours in the packet header. If a match occurs the    *
  141. * corresponding interface name is found by comparing the string in        *
  142. * port[] to the names assigned to interfaces with the attach command.     *
  143. * A pointer to the interface is returned by repeater. Default behavior on *
  144. * match failure is to return a pointer to the interface the packet came   *
  145. * in on. If our call is the last digi call in the header, the destination *
  146. * call is compared to the array of exception calls and, if a match, the   *
  147. * corresponding interface is returned by repeater. Default behavior on    *
  148. * match failure is to return a pointer to the interface referenced by the *
  149. * pseudo call "lan" in digilist.                                          *
  150. * If no matches at all are found, default behavior is to return a pointer *
  151. * to the interface the packet came in on.                                 *
  152. **************************************************************************/
  153. struct interface *
  154. repeater(ap,interface,hdr)
  155.      struct ax25_addr *ap;
  156.      struct interface *interface;
  157.      struct ax25 *hdr;
  158.  
  159. {
  160.      struct interface *intport;
  161.      int x, flg, match;
  162.  
  163.  if (++ap < &hdr->digis[hdr->ndigis]){
  164. #ifdef MULBUG
  165.                   printf("mport && there is a call after ours\n");
  166. #endif
  167.                   for (x=0, flg=0; (!flg) && (x <= 9) && (strcmp('\0',destrpt[x].dcall.call)!=0); x++){  /* 10 mports max */
  168. #ifdef MULBUG
  169.                     printf("stepping thru destrpt at %d %9.9s   %9.9s\n",x,ap->call,&(destrpt[x].dcall.call));
  170. #endif
  171.                       if (addreq(ap,&(destrpt[x].dcall))){
  172. #ifdef MULBUG
  173.                          printf("dcall match\n");
  174. #endif
  175.                          for (intport=ifaces; !flg && (intport!=NULLIF); intport=intport->next){
  176. #ifdef MULBUG
  177.                              printf("stepping thru interfaces %9.9s  %9.9s\n",intport->name,&(destrpt[x].port));
  178. #endif
  179.                              if (strcmp(intport->name,destrpt[x].port)==0){
  180. #ifdef MULBUG
  181.                                 printf("interface match on %s\n",&(destrpt[x].port));
  182. #endif
  183.                                 interface=intport;
  184.                                 flg = 1;
  185.                              }
  186.                          }
  187.                       }
  188.                   }
  189.                   ap--;
  190.                }
  191.                else{
  192.                    for (match=0,x=0, flg=0; (!flg) && (x <= 9) && (strcmp('\0',extbl[x].dcall.call)!=0); x++){  /* 10 mports max */
  193. #ifdef MULBUG
  194.                        printf("scanning for hdr.dest %9.9s  %9.9s\n",&(hdr->dest.call),&(extbl[x].dcall.call));
  195. #endif
  196.                        if (addreq(&(hdr->dest),&(extbl[x].dcall))){
  197. #ifdef MULBUG
  198.                           printf("dest match\n");
  199. #endif
  200.                           for (intport=ifaces; !flg && (intport!=NULLIF); intport=intport->next){
  201. #ifdef MULBUG
  202.                               printf("stepping thru interfaces %9.9s  %9.9s\n",intport->name,&(extbl[x].port));
  203. #endif
  204.                               if (strcmp(intport->name,extbl[x].port)==0){
  205. #ifdef MULBUG
  206.                                  printf("interface match\n");
  207. #endif
  208.                                  interface=intport;
  209.                                  flg = 1;
  210.                                  match=1;
  211.                               }
  212.                           }
  213.                       }
  214.                     }
  215.                     if (match!=1){
  216.                        for (x=0, flg=0; (!flg) && (x <= 9) && (strcmp('\0',destrpt[x].dcall.call)!=0); x++){  /* 10 mports max */
  217. #ifdef MULBUG
  218.                             printf("scanning for lan.dcall %9.9s  %9.9s\n",&(lan.dcall.call),&(destrpt[x].dcall.call));
  219. #endif
  220.                             if (addreq(&(lan.dcall),&(destrpt[x].dcall))){
  221. #ifdef MULBUG
  222.                                  printf("dcall match\n");
  223. #endif
  224.                                  for (intport=ifaces; !flg && (intport!=NULLIF); intport=intport->next){
  225. #ifdef MULBUG
  226.                                       printf("stepping thru interfaces %9.9s  %9.9s\n",intport->name,&(destrpt[x].port));
  227. #endif
  228.                                       if (strcmp(intport->name,destrpt[x].port)==0){
  229. #ifdef MULBUG
  230.                                           printf("interface match\n");
  231. #endif
  232.                                           interface=intport;
  233.                                           flg = 1;
  234.                                       }
  235.                                    }
  236.                              }
  237.                          }
  238.                       }
  239.                       ap--;
  240.                   }
  241. return(interface);
  242. }
  243. #endif
  244.  
  245.